//
//  XJMyWalletCell.m
//  XinJiangMall
//
//  Created by RaoBo on 2018/5/23.
//  Copyright © 2018年 Tzyang. All rights reserved.
//

#import "XJMyWalletCell.h"
@interface XJMyWalletCell()
@property(nonatomic, strong) UIImageView *iconIv;
@property(nonatomic, strong) UILabel *nameLabel;
@property(nonatomic, strong) UIImageView *arrowIv; // 箭头

@end
@implementation XJMyWalletCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

#pragma mark - 一 初始话
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        // 取消选中样式
//        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setupView];
    }
    return self;
}

- (void)setupView{
    [self.contentView addSubview:self.iconIv];
    [self.contentView addSubview:self.nameLabel];
    [self.contentView addSubview:self.arrowIv];
}

#pragma mark - 二 lazy
- (UIImageView *)iconIv {
    if (!_iconIv) {
        _iconIv = [[UIImageView alloc] init];
    }
    return _iconIv;
}

- (UILabel *)nameLabel{
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc] init];
    }
    return _nameLabel;
}

- (UIImageView *)arrowIv {
    if (!_arrowIv) {
        _arrowIv = [[UIImageView alloc] init];
        _arrowIv.image = [UIImage imageNamed:@"direction_right_black"];
        _arrowIv.contentMode =  UIViewContentModeScaleAspectFit;
    }
    return _arrowIv;
}


#pragma mark - 三 layout

- (void)layoutSubviews {
    [super layoutSubviews];
    
    [self.iconIv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(20);
        make.centerY.equalTo(self.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(30, 30));
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconIv.mas_right).offset(12);
        make.centerY.equalTo(self.contentView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(150, 30));
    }];
    
    [self.arrowIv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView.mas_right).offset(-20);
        make.centerY.equalTo(self.contentView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(15, 15));
    }];
    
//#ifdef __IPHONE_11_0
//    if(@available(iOS 11.0,*)){
//        [make.widthAnchor constraintEqualToConstant:10].active = YES;
//        [make.heightAnchor constraintEqualToConstant:20].active = YES;
//    }
//#endif
}

#pragma mark - 四 赋值
- (void)configMyWalletCellWithIcon:(NSString *)icon name:(NSString *)name {
    
    self.iconIv.image = [UIImage imageNamed:icon];
    
    self.nameLabel.text = name;
}
@end

